<template>
    <el-cascader :props="options" :style="styles" v-model="currentValue" :disabled="disabled"></el-cascader>
</template>
<script>
import Vue  from 'vue'
let sef=this;
export default {
    props:['id','styles','value','data','extype','isreadonly','appid'],
    name: "storage-select",
    data(){
        return {
            pId:'',
            cId:"",
           currentValue:this.value,
            disabled:false,
            options: {
                lazy: true,
                disabled:false,
                lazyLoad (node, resolve) { 
                    let level=node.level;
                    
                    if(level==0){
                        
                        const token=sessionStorage.getItem("token");
                         sef.$post("bygex",'byg/storageLoc/readRoomApi',{token:token}).then(data=>{
                           
                           
                            resolve(data);
                        })
                    }else{
                        let label=node.value;
                        
                        let data={};
                        const token=sessionStorage.getItem("token");
                        data.sRoom=label;
                        data.token=token;
                        let lg_id=localStorage.getItem("lg_id");
                        data.lg_id=lg_id;
                        sef.$post("bygex","byg/storageLoc/readLocItem",data).then(data=>{
                            let datas=[];
                            for(let i=0;i<data.length;i++){
                                let c_id=data[i].c_id;
                                let loc_ex2=data[i].loc_ex2;
                                let d={};
                                d.value=c_id;
                                d.label=loc_ex2;
                                d.leaf=true;
                                datas.push(d);
                            }
                             resolve(datas);
                        })
                    }
                    
                }
            }
        }
    }, 
    beforeCreate(){
        sef=this;
    },
    created(){
        let ids=this.id.split(".");
        if(ids.length>1){
            let p=ids[0];
            let id_=ids[1];
            this.pId=p;
            this.cId=id_;
            this.currentValue=unescape(this.data[p][id_]).split(",");
            console.log("this.currentValue=========================="+this.currentValue);
            localStorage.setItem("lg_id",this.currentValue[this.currentValue.length-1]);
        }
      
        if(this.extype=="checkStrictly"){
            this.options.checkStrictly=true;
        }
       
        if(this.isreadonly=='Y')
            this.disabled=true;
        
    },
    watch:{
        currentValue: function (val) { //currentValue值变动就向父组件传值
            let vals="";
            let id="";
            for(let i=0;i<val.length;i++){
                vals=vals=="" ? val[i]:vals+","+val[i];
                id=val[i];
            }
           /* let data={};
            data.id=this.id;
            data.val=vals;
            console.log("val==select=="+vals+"=="+this.id)
            this.$emit('input',JSON.stringify(data));
            this.$emit('on-change',JSON.stringify(data));
            */
            this.$set(this.data[this.pId],this.cId,vals);

           /* data={};
            data.id="jc.jc_ex8";
            data.val=id;
            this.$emit('input',JSON.stringify(data));
            this.$emit('on-change',JSON.stringify(data));*/

            
            this.$set(this.data["jc"],"jc_ex8",id);

        },
        value:function (val) { //对值进行验证
            
        }
    }
}
</script>